package LeetCode.LeetCode2;

/**
 * 矩阵置零
 * @author lumin
 * @date 2022/03/31 20:01
 **/
public class Num73 {
    public static void setZeroes(int[][] matrix) {
        //原数组的行
        int m = matrix.length;
        //原数组的列
        int n = matrix[0].length;
        //创建一个新的数组，用来记录原数组中0的位置
        //将原数组中0的位置在新数组中标记为true
        boolean[] row = new boolean[m];
        boolean[] col = new boolean[n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (matrix[i][j] == 0) {
                    row[i] = col[j] = true;
                }
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (row[i] || col[j]) {
                    matrix[i][j] = 0;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[][] arr = {{0,1,2,0},{3,4,5,2},{1,3,1,5}};
        setZeroes(arr);
    }
}